<template>
	<view class="" style="background-image: url('https://resourse.cnlhjt.com/upload/20220825/e42f22ecdab8bf0b678f4baf80b81dd3.png');
		background-repeat: no-repeat;
		background-size: 100% 380rpx;">
		<view class="">
			<!-- 2.0.19支持autoBack，默认为false -->
			<u-navbar leftText="我的车位" autoBack bgColor="#0B868E" leftIconColor="#fff">
			</u-navbar>
		</view>


		<view class="con-body">

			<view style="height: 40rpx;"></view>
			<view class="uni-flex-center">
				<view class="main-service uni-cell-90" style="padding-bottom: 10rpx; width: 96%; margin-left: 2%;">
					<view class="user-list">
						<view class="" style="padding-top: 10rpx;font-weight:bold;">
							<u-cell-group :border="false">
								<u-cell icon="https://resourse.cnlhjt.com/upload/20220825/651206a7d0688d69f6448bb5c016854c.png" :title="house" :border="false"
									isLink @click="showFloor = true"></u-cell>
							</u-cell-group>

						</view>
						<view
							style="padding-left: 20rpx; padding-right: 20rpx; padding-bottom: 20rpx; margin-top: 20rpx;"
							v-for="(item, index) in parkList">
							<view
								style="height: 310rpx;background-image: url('https://resourse.cnlhjt.com/upload/20220825/842eb77b9d36ce2eeaf4199d41b1c665.png'); background-size: 100% 310rpx; color: #FFFFFF;">
								<view style="margin-left: 85%;" v-if="item.type == 1">
									<u-icon name="https://resourse.cnlhjt.com/upload/20220825/a0f95b736a080041ddd8a194f60c4f66.png" size="25"></u-icon>
								</view>
								<view v-else style="height: 25px;"></view>
								<u-cell-group :border="false">
									<u-cell icon="https://resourse.cnlhjt.com/upload/20220825/cb1c7d16a8abc16c8bc21653d4526c64.png" :title="'停车位 ' + item.park"
										:border="false" :titleStyle="titleStyle">
									</u-cell>
									<u-cell icon="https://resourse.cnlhjt.com/upload/20220825/f56dce60c5cabc1807f5f896846b7fa1.png"
										:title="'有效期 ' + item.start_time + ' 至 ' + item.end_time"
										:titleStyle="titleStyle" :border="false">
									</u-cell>
								</u-cell-group>

								<view style="width: 20%; margin-right: 40rpx;float: right; margin-top: 10rpx;">
									<u-button size="small" color="#0B868E" type="primary" plain shape="circle"
										@click="intoPay(item.id)">车位缴费
									</u-button>
								</view>

								<view style="clear: both;"></view>
							</view>

						</view>
					</view>
				</view>
			</view>
			<u-toast ref="uToast" />
			<view style="height: 140rpx;"></view>
			<!-- 下拉工具 -->
			<u-action-sheet :show="showFloor" :actions="actionsFloor" title="请选择您的房产" @close="showFloor = false"
				@select="floorSelect">
			</u-action-sheet>
			<u-action-sheet :show="showPark" :actions="actionsPark" title="请选择您的身份" @close="showPark = false"
				@select="parkSelect">
			</u-action-sheet>
			<u-empty :show="showEmpty" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
			<u-button :customStyle="btnStyle" @click="showPark = true">租车位</u-button>
		</view>
	</view>
</template>

<script>
	import {
		getDefaultHouse,
		getFloor,
		getPark
	} from "@/service/userService.js";
	export default {
		data() {
			return {
				btnStyle: {
					width: '96%',
					borderRadius: '40rpx',
					marginLeft: '2%',
					backgroundImage: "url('https://resourse.cnlhjt.com/upload/20220825/d1aa35c1d129137d9b12c8f34e59c5bc.png')",
					backgroundSize: '100% 80rpx',
					color: '#FFFFFF',
					position: 'fixed',
					bottom: '40rpx'
				},
				titleStyle: {
					color: '#FFFFFF',
					marginLeft: '10rpx'
				},
				showFloor: false,
				showPark: false,
				actionsFloor: [],
				actionsPark: [{
						name: '租车位（我是业主）',
						value: 0
					},
					{
						name: '租车位（我是租户）',
						value: 1
					}
				],
				defaultHouse: '1',
				house: "龍舟一号院1号楼1单元101室",
				parkList: [],
				showEmpty: false
			}
		},
		onLoad() {
			getDefaultHouse().then(this.getDefaultHouse);
			getFloor().then(this.getHouse);
			getPark().then(this.getPark);
		},
		methods: {
			getHouse(e) {
				if (e.code == 200) {
					this.actionsFloor = e.result;
				} else {
					this.$refs.uToast.show({

						type: 'error',
						title: '失败',
						message: e.msg,
						complete() {
							uni.navigateTo({
								url:"/pagesMine/house/index"
							})
						}
					})
				}
			},
			getDefaultHouse(e) {
				if (e.code == 200) {
					this.house = e.result.house;
				} else {
					this.$refs.uToast.show({

						type: 'error',
						title: '失败',
						message: e.msg,
						complete() {
							uni.navigateBack({
								delta: 1
							})
						}
					})
				}
			},
			getPark(e) {
				if (e.code == 200) {
					this.parkList = e.result;
				} else {
					this.showEmpty = true;
				}
			},
			floorSelect(e) {
				this.house = e.name;
			},
			parkSelect(e) {
				console.log(e.value);
				console.log(e.name);
				if (e.value == 0) {
					this.$u.route({
						url: "/pagesMine/park/hire",
						params: {

						}
					})
				} else {
					this.$u.route({
						url: "/pagesMine/park/rent",
						params: {

						}
					})
				}
			},
			intoPay() {
				this.$u.route({
					url: "/pagesMine/park/pay",
					params: {

					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.l_title {
		font-size: 32rpx;
		color: #999999;
	}

	.d_content {
		color: #666666;
		font-size: 32rpx;
	}

	.d_view {
		margin-top: 30rpx;
	}
</style>
